local iori_jump_action = class('iori_jump_action',function()
	return display.newNode()
end)

function iori_jump_action:ctor()
	self:pos(display.cx,display.cy)
	self:setRotation(90)
	local frames = display.newFrames("iori2_%03d.png", 54, 14)

	self.iori = cc.Sprite:createWithSpriteFrame(frames[1]):addTo(self)

	--self.iori:pos(display.cx,display.cy)
	self.Shape = self.Shape or {}
	self.body = cc.PhysicsBody:create()
	self.iori:setPhysicsBody(self.body)
	self.body:setTag(120)
	--self.body:setCategoryBitmask(0x02)
	--self.body:setCollisionBitmask(0x02)
	--self.body:setContactTestBitmask(0xffffffff)
	self.body:retain()
	
	local spriteWidth = self.iori:getContentSize().width
	local spriteHeight = self.iori:getContentSize().height

	self.Shape[#self.Shape+1] = cc.PhysicsShapeBox:create(cc.size(88,64) ,cc.PHYSICSBODY_MATERIAL_DEFAULT , cc.p((spriteWidth-88)/2 - 28,(spriteHeight-64)/2 -4))

	self.Shape[#self.Shape+1] = cc.PhysicsShapeBox:create(cc.size(148,42),cc.PHYSICSBODY_MATERIAL_DEFAULT , cc.p((spriteWidth-148)/2 - 30,(spriteHeight-42)/2 - 20))

	self.Shape[#self.Shape+1] = cc.PhysicsShapeBox:create(cc.size(148,42),cc.PHYSICSBODY_MATERIAL_DEFAULT , cc.p((spriteWidth-148)/2 - 40,(spriteHeight-42)/2 - 20))

	self.Shape[#self.Shape+1] = cc.PhysicsShapeBox:create(cc.size(118,46),cc.PHYSICSBODY_MATERIAL_DEFAULT , cc.p((spriteWidth-118)/2 - 68,(spriteHeight-42)/2 - 24))

	self.Shape[#self.Shape+1] = cc.PhysicsShapeBox:create(cc.size(88,60),cc.PHYSICSBODY_MATERIAL_DEFAULT , cc.p((spriteWidth-88)/2 - 84,(spriteHeight-60)/2 - 14))

	self.Shape[#self.Shape+1] = cc.PhysicsShapeBox:create(cc.size(88,60),cc.PHYSICSBODY_MATERIAL_DEFAULT , cc.p((spriteWidth-88)/2 - 88,(spriteHeight-60)/2 - 14))

	self.Shape[#self.Shape+1] = cc.PhysicsShapeBox:create(cc.size(76,56),cc.PHYSICSBODY_MATERIAL_DEFAULT , cc.p((spriteWidth-76)/2 - 96,(spriteHeight-56)/2 - 14))

	self.Shape[#self.Shape+1] = cc.PhysicsShapeBox:create(cc.size(68,58),cc.PHYSICSBODY_MATERIAL_DEFAULT , cc.p((spriteWidth-68)/2 - 110,(spriteHeight-58)/2 - 14))

	self.Shape[#self.Shape+1] = cc.PhysicsShapeBox:create(cc.size(68,58),cc.PHYSICSBODY_MATERIAL_DEFAULT , cc.p((spriteWidth-68)/2 - 108,(spriteHeight-58)/2 - 14))

	self.Shape[#self.Shape+1] = cc.PhysicsShapeBox:create(cc.size(76,56),cc.PHYSICSBODY_MATERIAL_DEFAULT , cc.p((spriteWidth-76)/2 - 96,(spriteHeight-56)/2 - 14))

	self.Shape[#self.Shape+1] = cc.PhysicsShapeBox:create(cc.size(88,60),cc.PHYSICSBODY_MATERIAL_DEFAULT , cc.p((spriteWidth-88)/2 - 84,(spriteHeight-60)/2 - 14))

	self.Shape[#self.Shape+1] = cc.PhysicsShapeBox:create(cc.size(88,60),cc.PHYSICSBODY_MATERIAL_DEFAULT , cc.p((spriteWidth-88)/2 - 72,(spriteHeight-60)/2 - 14))

	self.Shape[#self.Shape+1] = cc.PhysicsShapeBox:create(cc.size(118,46),cc.PHYSICSBODY_MATERIAL_DEFAULT , cc.p((spriteWidth-118)/2 - 54,(spriteHeight-46)/2 - 20))

	self.Shape[#self.Shape+1] = cc.PhysicsShapeBox:create(cc.size(88,64),cc.PHYSICSBODY_MATERIAL_DEFAULT , cc.p((spriteWidth-88)/2 -30,(spriteHeight-64)/2 - 4))

	for i=1,14 do
		self.Shape[i]:setTag(i)
		self.Shape[i]:retain() 			--需要retain否则下一帧无法改变shape
		self.Shape[i]:setCategoryBitmask(3)
		self.Shape[i]:setCollisionBitmask(3)
		self.Shape[i]:setContactTestBitmask(3)
		--self.Shape[i]:setTag(130+i)
	end

	--]]

	self.body:addShape(self.Shape[1])

	local function replaceShape(number)
		local tag = number == 1 and 14 or number - 1
		self.body:removeShape(tag)
		self.body:addShape(self.Shape[number])
	end

	local seq = cc.Sequence:create(
			cc.DelayTime:create(0.8/14),
			cc.CallFunc:create(function() replaceShape(2) end),
			cc.DelayTime:create(0.8/14),
			cc.CallFunc:create(function() replaceShape(3) end),
			cc.DelayTime:create(0.8/14),
			cc.CallFunc:create(function() replaceShape(4) end),
			cc.DelayTime:create(0.8/14),
			cc.CallFunc:create(function() replaceShape(5) end),
			cc.DelayTime:create(0.8/14),
			cc.CallFunc:create(function() replaceShape(6) end),
			cc.DelayTime:create(0.8/14),
			cc.CallFunc:create(function() replaceShape(7) end),
			cc.DelayTime:create(0.8/14),
			cc.CallFunc:create(function() replaceShape(8) end),
			cc.DelayTime:create(0.8/14),
			cc.CallFunc:create(function() replaceShape(9) end),
			cc.DelayTime:create(0.8/14),
			cc.CallFunc:create(function() replaceShape(10) end),
			cc.DelayTime:create(0.8/14),
			cc.CallFunc:create(function() replaceShape(11) end),
			cc.DelayTime:create(0.8/14),
			cc.CallFunc:create(function() replaceShape(12) end),
			cc.DelayTime:create(0.8/14),
			cc.CallFunc:create(function() replaceShape(13) end),
			cc.DelayTime:create(0.8/14),
			cc.CallFunc:create(function() replaceShape(14) end),
			cc.DelayTime:create(0.8/14),
			cc.CallFunc:create(function() replaceShape(1) end)
		)

	self.spawn = cc.Spawn:create({cc.Animate:create(display.newAnimation(frames, 0.8/#frames)),seq})
	self.repeatAnimate = cc.RepeatForever:create(self.spawn)
	self.iori:runAction(self.repeatAnimate)
	--self.iori:playAnimationForever(display.newAnimation(frames, 0.8/#frames))
	--self.iori:stopAction(self.repeatAnimate)
	--self.iori:runAction(self.spawn)
	--[[
	-- 测试replaceShape函数
	--local num = 2
	local buttom = cc.ui.UIPushButton.new({normal = 'CloseNormal.png',pressed = 'CloseSelected.png'},{scale9=true})
				:onButtonClicked(function(event)
					print('... onButtonClicked ...')
					--replaceShape(num)
					--num = num + 1
				end)
				:addTo(self)
				:pos(display.cx,display.cy+200)
	]]

	--printf('iori_jump.body:setCategoryBitmask = %d',self.body:getCategoryBitmask())
end

return iori_jump_action